package com.allwinter.yibangsafe.controller;

import com.alibaba.fastjson.JSONObject;
import com.allwinter.yibangsafe.service.myServiceService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/service")
@CrossOrigin(origins = "*")
public class MyServiceController {

    @Autowired
    private myServiceService myServiceService;

    @GetMapping("/allService")
    @ResponseBody
    public JSONObject getAllService(){
        JSONObject allService = myServiceService.getAllService();
        return allService;
    }

    @GetMapping("/ServicePage")
    @ResponseBody
    public JSONObject getServicePage(@Param("nowPage")int nowPage, @Param("pageSize")int pageSize){
        System.out.println("nowPage :" + nowPage);
        System.out.println("pageSize :" + pageSize);
        JSONObject allService = myServiceService.selectByPage(nowPage,pageSize);
        return allService;
    }

    @GetMapping("/getOneService")
    @ResponseBody
    public JSONObject getOneServiceById (String serviceId) {
        System.out.println("serviceId---------->" + serviceId);
        JSONObject res = new JSONObject();
        Long serviceid = Long.parseLong(serviceId);
        JSONObject byServiceId = myServiceService.getByServiceId(serviceid);
        System.out.println(byServiceId.toString());
        return byServiceId;
    }
}
